<?php
// +----------------------------------------------------------------------
// | ThinkSNS
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.thinksns.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Nonant <nonant@163.com>
// +----------------------------------------------------------------------

class AdminAction extends Administrator{
	function index(){
		$m = D('Bug');
		$list = $m->where($map)->findpage(10);
		$this->assign($list);
		$this->display();
	}
	
	function category(){
		$m = D('Category');
		$this->assign('list',$m->findall());
		$this->display();
	}
	
	function docategory(){
		$m = D('Category');
		switch ($_REQUEST['type']){
			case 'add':
				$strTitle = h($_POST['title']);
				if (empty($strTitle)) {
					$this->error('分类名不能为空');
					break;
				}
				$map['title'] = $strTitle;
				$count = $m->where($map)->count();
				if($count){
					$this->error('分类名已存在');
				}else{
					$m->add($map);
					$this->redirect('category');
				}
			break;
			
			case 'update':
				foreach ($_POST['title'] as $key=>$val){
					$m->setField('title',$val,'id='.$key);
				}
				$this->redirect('category');
			break;
			
			case 'del':
				$m->where('id='.intval($_REQUEST['id']))->delete();
				$this->redirect('category');
			break;
		}
	}
	
	function edition(){
		$m = D('Edition');
		$this->assign('list',$m->findall());
		$this->display();
	}
	
	function doedition(){
		$m = D('Edition');
		switch ($_REQUEST['type']){
			case 'add':
				$strTitle = h($_POST['title']);
				if (empty($strTitle)) {
					$this->error('版本不能为空');
					break;
				}
				$map['title'] = $strTitle;
				$count = $m->where($map)->count();
				if($count){
					$this->error('版本已存在');
				}else{
					$m->add($map);
					$this->redirect('edition');
				}
			break;
			
			case 'update':
				foreach ($_POST['title'] as $key=>$val){
					$m->setField('title',$val,'id='.$key);
				}
				$this->redirect('edition');
			break;
			
			case 'del':
				$m->where('id='.intval($_REQUEST['id']))->delete();
				$this->redirect('edition');
			break;
		}
	}	
}
